package com.model;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.util.DB;

public class Customer {
//	private Connection conn = DB.getConnection();
	private Connection conn = DB.con;
	private int id;
	private String customerNo;
	private String customerName;
	private String telephone;
	private String address;

	// 获取customer
	public Customer getCustomer(String customerNo) {
		// TODO Auto-generated method stub
		PreparedStatement st = null;
		Customer customer = null;
		try {
			st = conn
					.prepareStatement("select * from customer where CUSTOMERNO = ?");
			st.setString(1, customerNo);
			ResultSet rs = st.executeQuery();
			while (rs.next()) {
				customer = new Customer();
				customer.setId(rs.getInt("ID"));
				customer.setCustomerNo(rs.getString("CUSTOMERNO"));
				customer.setCustomerName(rs.getString("CUSTOMERNAME"));
				customer.setTelephone(rs.getString("TELEPHONE"));
				customer.setAddress(rs.getString("ADDRESS"));
			}
			return customer;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getCustomerNo() {
		return customerNo;
	}

	public void setCustomerNo(String customerNo) {
		this.customerNo = customerNo;
	}

	public String getCustomerName() {
		return customerName;
	}

	public void setCustomerName(String customerName) {
		this.customerName = customerName;
	}

	public String getTelephone() {
		return telephone;
	}

	public void setTelephone(String telephone) {
		this.telephone = telephone;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	@Override
	public String toString() {
		return "Customer [id=" + id + ", customerNo=" + customerNo
				+ ", customerName=" + customerName + ", telephone=" + telephone
				+ ", address=" + address + "]";
	}

}
